package com.emin.platform.subjectcenter.entity;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Yong
 * @name 主体信息类
 * @date 2017-10-23
 * @since 1.0.1
 */
@Entity
@Table(name = "emin_ecm", schema = "ecmcenter")
public class Ecm extends BaseicEntity {

    public static final String ECM_ID = "id";

    public static final String ECM_NAME = "name";

    public static final String ECM_SN = "sn";

    public static final String PROP_INDUSTORY_ID = "industories.id";

    private static final long serialVersionUID = 3346762236127374182L;

    @Id
    @Override
    @Column(length = 20)
    @SequenceGenerator(name = "ecm_id_seq", sequenceName = "public.ecm_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ecm_id_seq")
    public Long getId() {
        return super.getId();
    }


    @Override
    public void setId(Long aLong) {
        super.setId(aLong);
    }

    /**
     * 主体的图标
     **/
    @Column(name = "ecm_logo", length = 225)
    private String logo;

    /**
     * 主体名称
     **/
    @NotNull
    @Column(name = "ecm_name", length = 20, unique = true)
    private String name;

    /**
     * 主体方代码
     **/
    @NotNull
    @Column(name = "ecm_sn", length = 20, unique = true)
    private String sn;


    /**
     * 主体地址
     **/
    @Column(name = "ecm_address")
    private String address;


    /**
     * 激活还是禁用状态
     **/
    private int activeStatus;

    private List<Industory> industories = new ArrayList<>();

    @Column(name = "ecm_describe", columnDefinition = "text")
    private String describe;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(schema = "ecmcenter", name = "emin_ecm_industory", joinColumns = {
            @JoinColumn(name = "ecm_id", referencedColumnName = "id")
    }, inverseJoinColumns = {
            @JoinColumn(name = "industory_id", referencedColumnName = "id")
    })
    @Fetch(FetchMode.SELECT)
    public List<Industory> getIndustories() {
        return industories;
    }


    @Column(name = "ecm_logo", length = 225)
    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    @NotNull
    @Column(name = "ecm_name", length = 20, unique = true)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @NotNull
    @Column(name = "ecm_sn", length = 20, unique = true)
    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    @Column(name = "ecm_address")
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setIndustories(List<Industory> industories) {
        this.industories = industories;
    }

    @Column(name = "ecm_describe", columnDefinition = "text")
    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }


    @Column(name = "ecm_active_status", length = 1, columnDefinition = "Int default 0")
    public int getActiveStatus() {
        return activeStatus;
    }

    public void setActiveStatus(int activeStatus) {
        this.activeStatus = activeStatus;
    }
}
